#pragma once
#include "longinstance.h"
#include "neighborhood2.h"

class FreeFormRule;
class LongInstance2B;


//*****************************************************************************************
// THIS CLASS has a vector of Neighborhood pointers, each pointing to a Neighborhood2 object. 
// It is damn important to delete the Neighborhood2 objects whenever removing an element
// from the vector or clearing it. Risk of stupid memory leak.
//*****************************************************************************************
//ALSO NOTE: It is extended from LongInstance, LongInstance default constructor will be
//called each time any of the constructors are called.


/** 
 * Similar to LongInstance, the only difference is that it adds Neighbourhood2 objects 
 * when adding a new phase to the LongInstance.
 */
class LongInstance2: public LongInstance
{
public:
	void addPhase (const Neighborhood2* newNB, int newLabel);
	void addPhase (const ImageMatrix& image, int row, int col, int nbRadius, int newLabel);
	int getFeatureSize() const;

	bool hasSameFeature (const LongInstance2&) const;		//!< Returns true if the feature array of both objects have the same elements.
	///we need these two for finding the conflicts in a rulebase.
	bool hasSameFeature (const vector<Neighborhood*>& nb) const;	//!< Returns true if this longinstance has the same features as the given neighborhood vector.

	int getFeature (int neighborhoodIndex, int featureIndex) const;
	int getFeature (int longFeatureIndex) const;
	
	/** returns the size of one neighborhood in the objects, i.e. the number of features in any of the neighborhoods.*/
	int getNeighborhoodSize(void) const;

	LongInstance2 (const LongInstance2& other);
	
	/** Creates the object from a provided array strings of a known length and a label
	 \param nbStr an array of strings, each corresponding one neighborhood in the IF part.
	 each string in the array is a string of 0s and 1s, not separated by anything. 
	 \param strNum The number of strings, equal to number of neighborhoods.
	 This function select the chunk of the string for each Neighborhood2 based on the size of NRADIUS.*/
	LongInstance2 (string* nbStr, int strNum, int label, int radius = NRADIUS);

	LongInstance2();

	~LongInstance2();

	friend void ConvertLI2BtoLI2 (const LongInstance2B& li2b, LongInstance2& li2);
	friend void ConvertFFRtoLI2  (const FreeFormRule& ffr,    LongInstance2& li2);

};